package com.thinkit.bigdata.web.model.result;

import java.io.Serializable;
import java.util.ArrayList;

/**
 *
 * Created by hccl on 2018/9/4.
 * 状态码:
 *      -1 : 请求错误
 *      0 : 请求成功
 *      9999 : 仅提示信息
 */
public class HtmlResult implements Serializable {
    private static final long serialVersionUID = 1L;

    private String msg;
    private Integer code;
    private Object count;

    public static HtmlResult success() {
        HtmlResult result = new HtmlResult();
        result.setCode(0);
        return result;
    }

    public static HtmlResult failure() {
        HtmlResult result = new HtmlResult();
        result.setCode(-1);
        return result;
    }

    public static HtmlResult failure(String message) {
        Hresult result = new Hresult(new ArrayList<>());
        result.setCode(-1);
        result.setMsg(message);
        return result;
    }

    public static HtmlResult tips(Object data) {
        Hresult result = new Hresult(data);
        result.setCode(9999);
        return result;
    }

    public static HtmlResult success(Object data) {
        Hresult result = new Hresult(data);
        result.setCode(0);
        return result;
    }

    public static HtmlResult success(Object data, String message) {
        Hresult result = new Hresult(data);
        result.setCode(0);
        result.setMsg(message);
        return result;
    }

    public static HtmlResult success(Object data, Object count) {
        Hresult result = new Hresult(data);
        result.setCode(0);
        result.setCount(count);
        return result;
    }

    public static HtmlResult success(String message) {
        Hresult result = new Hresult(new ArrayList<>());
        result.setCode(0);
        result.setMsg(message);
        return result;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getCount() {
        return count;
    }

    public void setCount(Object count) {
        this.count = count;
    }

    @Override
    public String toString() {
        return "{" +
                "\"msg\" :\"" + msg + '\"' +
                ", \"code\" : " + code +
                '}';
    }
}
